package com.ethan.modules.organization.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.ethan.common.orm.model.IDModel;

/**
 * 部门实体类
 * 
 * @author liangjw(liangjw@huizhengtech.com)
 * @version 1.0
 * 
 */
@Entity
@Table(name = "tz_wf_test_dept")
public class Department extends IDModel {
	private static final long serialVersionUID = -7521905552650688072L;
	private String deptname;
	private String deptManager; // 部门管理员
	private int parentDeptId; // 父部门id
	private String deptCode; // 部门编码
	private int orderno; // 顺序号
	private List<User> users = new ArrayList<User>();

	@Column(name = "deptname",length = 40)
	public String getDeptname() {
		return deptname;
	}

	public void setDeptname(String deptname) {
		this.deptname = deptname;
	}

	@Column(name = "deptManager", length = 40)
	public String getDeptManager() {
		return deptManager;
	}

	public void setDeptManager(String deptManager) {
		this.deptManager = deptManager;
	}
	
	@Column(name = "parentDeptId")
	public int getParentDeptId() {
		return parentDeptId;
	}

	public void setParentDeptId(int parentDeptId) {
		this.parentDeptId = parentDeptId;
	}
	
	@Column(name = "deptCode", length = 50)
	public String getDeptCode() {
		return deptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}

	@Column(name = "orderno")
	public int getOrderno() {
		return orderno;
	}

	public void setOrderno(int orderno) {
		this.orderno = orderno;
	}
	
    // cascade表示级联操作   
    // CascadeType.MERGE级联更新：若items属性修改了那么order对象保存时同时修改items里的对象。对应EntityManager的merge方法   
    // CascadeType.PERSIST级联刷新：获取order对象里也同时也重新获取最新的items时的对象。对应EntityManager的refresh(object)方法有效。即会重新查询数据库里的最新数据   
    // CascadeType.REFRESH级联保存：对order对象保存时也对items里的对象也会保存。对应EntityManager的presist方法   
    // CascadeType.REMOVE级联删除：对order对象删除也对items里的对象也会删除。对应EntityManager的remove方法   
    // FetchType.LAZY表示懒加载。对于xxxtoMany时即获得多的一方fetch的默认值是FetchType.LAZY懒加载。对于xxxtoOne时即获得一的一方fetch的默认值是FetchType.EAGER立即加载   
    // mappedBy="classes"就相当于inverse=true,(mappedBy指定的是不需要维护关系的一端)      
    //请检查orderItems这个属性是否使用了泛型,如:Set<Student>.
    //如果未使用泛型,请在OneToMany注释中使用targetEntity指定元素的类型
	@OneToMany(cascade = { CascadeType.ALL}, fetch = FetchType.LAZY ,
			targetEntity = User.class,mappedBy="dept")
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	

}
